`
https://leetcode.cn/problems/deepest-leaves-sum/
`

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var deepestLeavesSum = function (root) {
  if (root === null) return 0;
  const q = [];
  q.push(root);

  let sum = 0;
  while (q.length > 0) {
    sum = 0;
    const sz = q.length;
    for (let i = 0; i < sz; i++) {
      const cur = q.shift();
      // 累加一层的节点之和
      sum += cur.val;
      if (cur.left !== null)
        q.push(cur.left);
      if (cur.right !== null)
        q.push(cur.right);
    }
  }
  // 现在就是最后一层的节点值和
  return sum;
};